<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<link rel="stylesheet" media="screen" href="css/docs.css"/>
<link rel="stylesheet" media="screen" href="lib/jqplot/jquery.jqplot.min.css"/>
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>

<link rel="stylesheet" type="text/css" href="${ctx}/css/tipswindown.css"/>
<script type="text/javascript" src="${ctx}/js/tipswindown.js"></script>

<script type="text/javascript" src="${ctx}/js/global_util.js"></script>

<h1 class="page-title">离职项目管理 - ${project == null ? "添加" : "修改"}</h1>

<div class="container_12 clearfix leading">
    <div class="side grid_12 leading">
        <form class="form has-validation" id="post_form" name="post_form">
            <div class="clear"></div>
            <div class="clearfix">
                <label for="p_name" class="form-label">项目名称  <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="p_name" name="project.name" required="required" placeholder="请输入项目名称" value='${project.name}'/>
                </div>
            </div>

            <div class="clear"></div>
            <div class="clearfix">
                <label for="p_content" class="form-label">项目内容  <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="p_content" name="project.content" required="required" placeholder="请输入项目内容" value='${project.content}'/>
                </div>
            </div>

            <div class="clear"></div>
            <div class="clearfix">
                <label class="form-label">选择审核人   <em>*</em></label>
                <div class="form-input">
                    <input type="hidden" id="employee_id" name="project.auditor.id" required="required" value='${project.auditor.id}'/>
                    <span style="font-weight: 800;font-size: 16px;margin-right: 10px;margin-left:5px;display: none;" id="employee_name"></span>
                    <a href="javascript:onShowDiv('data_input')" style=" margin-top:10px" class="button"><span class="icon" style="background:url(${ctx}/images/img/add.png)">&nbsp;</span>选择</a>
                </div>
            </div>

            <div class="clear"></div>
            <div class="clearfix">
                <label for="p_remark" class="form-label">备注  <em>*</em></label>
                <div class="form-input">
                    <textarea name="project.remark" rows="5" required="required" id="p_remark" placeholder="请输入项目备注">${project.remark}</textarea>
                </div>
            </div>

            <input type="hidden" name="project.id" value="${project.id}">
            <input type="hidden" name="project.organization.id" value="${organizationId}">
            <div class="form-action clearfix">
                <button class="button" type="button" onclick="checkForm()">${project == null ? "申请" : "修改"}</button>
                <button class="button" type="reset">重置</button>
                <a class="button" href="#leave/project-main.xhtml"><span style="background:url(${ctx}/images/img/arrow_undo.png)" class="icon">&nbsp;</span>返回</a>
            </div>
        </form>
    </div>
</div>

<div class="clear"></div>

<script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript">
    $(function(){
        if("${project != null}" == "true"){
            $("#employee_name").html("${project.auditor.name}");
            $("#employee_name").show();
        }
    });

    //显示员工选择框
    function onShowDiv(type) {
        tipsWindown("选择员工", "url:post?${ctx}/employee/staff_list.xhtml?operation=select&organizationId=${organizationId}", "900", "350", "true", "", "true", "text");
    }
    //员工选择框返回事件
    function onSelectEployee(eid, ename) {
        if (eid == undefined || ename == undefined) {
            return;
        }
        $("#employee_id").val(eid);
        $("#employee_name").show();
        $("#employee_name").html(ename);
    }

    function checkForm() {
        var p_name = $("#p_name").val();
        if (checkNull(p_name)) {
            alert("请输入项目名称");
            return;
        }
        var p_content = $("#p_content").val();
        if (checkNull(p_content)) {
            alert("请输入项目内容");
            return;
        }
        var employee_id = $("#employee_id").val();
        if (checkNull(employee_id)) {
            alert("请选择审核人");
            return;
        }
        var p_remark = $("#p_remark").val();
        if (checkNull(p_remark)) {
            alert("请输入项目备注");
            return;
        }

        var data = $("#post_form").serialize();
        var url = "${ctx}/leave/project-save.xhtml";
        $.ajax(url, {
            type:"POST",
            data:data,
            dataType:"html",
            cache:false,
            success:function (a) {
                return pageDownloaded(a, url)
            },
            complete:function () {
            }
        });
    }
</script>